package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.BrowsingHistory;
import com.atguigu.lease.web.app.mapper.BrowsingHistoryMapper;
import com.atguigu.lease.web.app.service.BrowsingHistoryService;
import com.atguigu.lease.web.app.vo.history.HistoryItemVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author liubo
 * @description 针对表【browsing_history(浏览历史)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
@RequiredArgsConstructor
public class BrowsingHistoryServiceImpl extends ServiceImpl<BrowsingHistoryMapper, BrowsingHistory>
        implements BrowsingHistoryService {
    private final BrowsingHistoryMapper browsingHistoryMapper;
    @Override
    public IPage<HistoryItemVo> getHistoryItemVo(Page<HistoryItemVo> page,Long userId) {
        return browsingHistoryMapper.getHistoryItemVo(page,userId);
    }

    //
    @Async
    //异步的
    @Override
    public void saveHistory(Long userId, Long id) {
        /*BrowsingHistory history = lambdaQuery()
                .eq(BrowsingHistory::getRoomId, id)
                .eq(BrowsingHistory::getUserId, userId)
                .one();*/
        BrowsingHistory history1=new BrowsingHistory();
        history1.setRoomId(id);
        history1.setUserId(userId);
        history1.setBrowseTime(new Date());
        saveOrUpdate(history1);
        /*if(history==null)
        {
            save(history1);
        }
        else {
            up
        }*/
    }
}